// yb_mingpian/pages/paycontent/userorder/index.js

var app = getApp(),
  api = app.requirejs("api/index"),
  core = app.requirejs("core");

Page({

  data: {
    list: [],
    page: 1,
    end: false,
  },

  onLoad: function(options) {

    var that = this,
      e = {};
    that.order_info();
  },
  del_order: function(e) {
    var that = this,ii=core.pdata(e);
    core.get("paycontent/order_del", {
      uid: app.getCache("userinfo").uid,
      order_id: ii["id"]
    }, function(t) {
      if (t.code == 1) {
        core.alert("删除成功");
        that.setData({
          page: 1
        })
        that.order_info();
      } else {
        core.alert("删除失败")
      }
    }, true)
  },
  order_info: function() {
    var that = this,
      e = {};
      core.get("paycontent/order", {
        uid: app.getCache("userinfo").uid,
        page: that.data.page
      }, function (t) {
        if (t.code == 1) {
          if (t.info.length > 0) {

            if (that.data.page == 1) {
              e.list = t.info;
            } else {
              e.list = that.data.list.concat(t.info);
            }
            e.page = that.data.page + 1;
            that.setData(e);
            if (t.info.length < 10) {
              that.setData({
                end: true
              });
            }
          } else {
            that.setData({
              end: true
            });
          }

        } else {
          core.alert(t.msg)
        }
      }, true)

  },

  onShow: function() {

  },

  onHide: function() {

  },

  onUnload: function() {

  },

  onPullDownRefresh: function() {

  },

  onReachBottom: function() {
    if (!this.data.end) {
      this.order_info();
    }
  },

  // onShareAppMessage: function() {
  //
  // }
})